
var Chain3 = require('chain3');

var chain3 = new Chain3(new Chain3.providers.HttpProvider('http://localhost:8545'));  //设置API访问moac节点方式


var chain3Ver = chain3.version.network;                //查看当前moac网络ID
console.log('chain3 Version  :'+ chain3Ver);

var apiVer1 = chain3.sha3("some string to be hashed"); //该算法将传入的字符串进行哈希运算
console.log('hashed string  :'+ apiVer1);

var apiVer4 = chain3.mc.coinbase;                      //节点配置的，如果挖矿成功奖励发送到该地址
console.log('client listening  :'+ apiVer4);

var apiVer5 = chain3.mc.accounts;                      //节点持有的账户列表
console.log('accounts  :'+ apiVer5);

var apiVer6 = chain3.mc.blockNumber;                   //当前区块号
console.log('blockNumber  :'+ apiVer6);

var apiVer7 = chain3.mc.getBalance("0x7567f6e7a8017fe8fd18eab70e36b3d2f68c2301");
console.log('getBalance1  :'+ apiVer7);                //给定地址的余额
console.log('getBalance2  :'+ apiVer7.toString(10));
//console.log('getBalance3  :'+ apiVer7.toNumber);

var apiVer8 = chain3.mc.defaultBlock;                  //默认块设置，默认值是latest，即最近刚出的区块
console.log('default block  :'+ apiVer8);

//chain3.mc.defaultBlock = 123;                        //传入一个值来覆盖默认配置
//console.log('default block  :'+ chain3.mc.defaultBlock);

var apiVer9 = chain3.mc.gasPrice;                      //该值由最近几个块的gas价格的中值决定
console.log('gasprice  :'+ apiVer9.toString(10));

var apiVer13 = chain3.mc.getBlockTransactionCount(26190);//指定区块的交易数量
console.log('get block transaction count  :'+ apiVer13);
//JSON.stringify(apiVer13);

var apiVer14 = chain3.mc.getBlock(26190);              //返回制定区块号或区块hash所对应的区块
console.log('getblock  :'+ JSON.stringify(apiVer14));

var apiVer17 = chain3.mc.syncing;                      //同步状态，如果正在同步，返回同步对象，如同步开始区块号、节点当前正在同步的区块号等
console.log('get syncing  :'+ apiVer17);               //否则返回false


//部署合约成功后得到合约地址的hash，从hash得到合约地址
hash = "0x0652e288e3f36618ce1c97e19d34948eafe5448f20ff84ec3264d8b935c6b529";
var receipt = chain3.mc.getTransactionReceipt(hash);
console.log('from hash to contract address  :'+ JSON.stringify(receipt));

